Skip to content

查找图片1 - FindImageFromPathAll

函数简介

在指定图片中查找指定图像的所有匹配位置,源图与模板均通过文件路径指定,返回全部匹配结果。

接口名称

FindImageFromPathAll

DLL调用

long FindImageFromPathAll(long instance, string source, string templ, string deltaColor, double matchVal);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
source字符串源图片的路径
templ字符串模板图片的路径,可以是多个图片,如"test.bmp|test2.bmp|test3.bmp"
deltaColor字符串颜色差值,格式为"RRGGBB",如"101010"
matchVal双精度浮点数相似度,如0.85,最大为1

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
auto results = ola.FindImageFromPathAll("images/scene.png", "img/btn_ok.bmp", "101010", 0.9);
if (!results.empty() && results[0].MatchState) {
    int x = results[0].X;
    int y = results[0].Y;
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
var results = ola.FindImageFromPathAll("images/scene.png", "img/btn_ok.bmp", "101010", 0.9);
if (results.Count > 0 && results[0].MatchState)
{
    int x = results[0].X;
    int y = results[0].Y;
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
results = ola.FindImageFromPathAll("images/scene.png", "img/btn_ok.bmp", "101010", 0.9)
if results and results[0].get("MatchState"):
    x = results[0]["X"]
    y = results[0]["Y"]
java
import com.olaplug.OLAPlugServer;
import com.olaplug.model.MatchResult;
import java.util.List;

OLAPlugServer ola = new OLAPlugServer();
List<MatchResult> results = ola.FindImageFromPathAll("images/scene.png", "img/btn_ok.bmp", "101010", 0.9);
if (results != null && !results.isEmpty() && results.get(0).MatchState) {
    int x = results.get(0).X;
    int y = results.get(0).Y;
}
cpp
var ola = com("OlaPlug.OlaSoft")
var results = ola.FindImageFromPathAll("images/scene.png", "img/btn_ok.bmp", "101010", 0.9)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
results = ola.FindImageFromPathAll("images/scene.png", "img/btn_ok.bmp", "101010", 0.9)
text
.局部变量 ola, OLAPlug
ola.创建 ()
results = ola.FindImageFromPathAll("images/scene.png", "img/btn_ok.bmp", "101010", 0.9)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var results = ola.FindImageFromPathAll("images/scene.png", "img/btn_ok.bmp", "101010", 0.9);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
MatchDataList results = ola.FindImageFromPathAll("images/scene.png", "img/btn_ok.bmp", "101010", 0.9)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
auto results = ola.FindImageFromPathAll("images/scene.png", "img/btn_ok.bmp", "101010", 0.9);
if (!results.empty() && results[0].MatchState) {
    int32_t x = results[0].X;
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long ptr = FindImageFromPathAll(instance, "images/scene.png", "img/btn_ok.bmp", "101010", 0.9);
if (ptr != 0) {
    char json[8192] = {0};
    GetStringFromPtr(ptr, json, sizeof(json));
    int matchState = 0, x = 0, y = 0, width = 0, height = 0, index = 0;
    double matchVal = 0, angle = 0;
    ParseMatchImageAllJson(instance, json, 0, &matchState, &x, &y, &width, &height, &matchVal, &angle, &index);
    FreeStringPtr(instance, ptr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long FindImageFromPathAll(long ola, string source, string templ, string deltaColor, double matchVal);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int ParseMatchImageAllJson(string str, int parseIndex, out int matchState, out int x, out int y, out int width, out int height, out double matchVal, out double angle, out int index);

long instance = CreateCOLAPlugInterFace();
long ptr = FindImageFromPathAll(instance, "images/scene.png", "img/btn_ok.bmp", "101010", 0.9);
if (ptr != 0) {
    StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
    GetStringFromPtr(ptr, sb, sb.Capacity);
    FreeStringPtr(ptr);
    ParseMatchImageAllJson(sb.ToString(), 0, out int matchState, out int x, out int y, out int w, out int h, out double mv, out double ang, out int idx);
}
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ptr = ola.FindImageFromPathAll(instance, ...)
# 原生返回 JSON 数组指针,用 ParseMatchImageAllJson(instance, json, 0, ...) 取第一项

返回值

字符串指针,返回JSON数组格式的所有匹配结果。DLL调用返回字符串指针地址,需要调用 FreeStringPtr 接口释放内存。

返回数据格式:

json
[{
    "MatchVal": 0.85,
    "MatchState": true,
    "Index": 0,
    "X": 100,
    "Y": 200,
    "Width": 100,
    "Height": 100
}]
字段名类型说明
MatchVal浮点数匹配相似度。
MatchState布尔是否匹配成功。
Index整数结果索引(从 0 开始)。
X整数X 坐标。
Y整数Y 坐标。
Width整数宽度。
Height整数高度。